/*
 * Tablero.java
 *
 * Created on 30 de mayo de 2009, 03:21 PM
 */
package gui;

import conexion.SocketClient;
import conexion.SocketListener;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import mundo.Baraja;
import mundo.Carta;

/**
 *
 * @author  Arquitectura
 */
public class Tablero_1 extends javax.swing.JFrame implements SocketListener {

    private SocketClient socket;
    private String puntaje;
    private String puntajeAnfitrion;
    private int empates;
    private ArrayList<String> jugadores;
    private ArrayList<String> puntajes;
    private InformeJuego ij;
    private Baraja baraja;
    private ArrayList<Carta> cartas;
    private Home gc;
    //private ArrayList<Carta> jugada;

    /** Creates new form Tablero */
    public Tablero_1(Home gc) {
        initComponents();

        this.gc=gc;

        xPnlFondo pnlFondo = new xPnlFondo(9);
        this.add(pnlFondo);
        this.pack();
        this.setSize(800, 635); //El 635 depende (alto) depende del Skin usado.
        this.setLocationRelativeTo(null);

        empates = 0;
        this.jugadores = new ArrayList();
        this.puntajes = new ArrayList();
        //this.Iniciar("localhost", 1414);
        baraja = new Baraja();
        cartas = baraja.getBaraja();
        puntaje=new String("0");
    puntajeAnfitrion=new String("0");
    //this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jlJugador1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtMesa = new javax.swing.JTextArea();
        jlTurno = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jbRealizar = new javax.swing.JButton();
        jbConsultar = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jbAbandonar = new javax.swing.JButton();
        jlTitulos = new javax.swing.JLabel();
        jlPuntos = new javax.swing.JLabel();
        jcOpcion = new javax.swing.JComboBox();
        jcCaracteristica = new javax.swing.JComboBox();
        BTN_cartaRemota = new javax.swing.JButton();
        BTN_cartaLocal = new javax.swing.JButton();
        jlJugador2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jlJugador1.setText("jLabel1");

        jtMesa.setColumns(20);
        jtMesa.setEditable(false);
        jtMesa.setRows(5);
        jScrollPane1.setViewportView(jtMesa);

        jPanel1.setOpaque(false);

        jbRealizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_realizarJugada.png"))); // NOI18N
        jbRealizar.setEnabled(false);
        jbRealizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRealizarActionPerformed(evt);
            }
        });

        jbConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_ConsultarInforme.png"))); // NOI18N
        jbConsultar.setEnabled(false);
        jbConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbConsultarActionPerformed(evt);
            }
        });

        jbAbandonar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_cancelar_roll.png"))); // NOI18N
        jbAbandonar.setEnabled(false);
        jbAbandonar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAbandonarActionPerformed(evt);
            }
        });

        jlTitulos.setText("Puntos");

        jcOpcion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-", "A la Mayor", "A la Menor" }));
        jcOpcion.setEnabled(false);

        jcCaracteristica.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-", "Duracion de Pelicula", "Galardones Ganados", "Año de Lanzamiento", "Dinero Recaudado", "Presupuesto" }));
        jcCaracteristica.setEnabled(false);

        BTN_cartaRemota.setBorder(null);
        BTN_cartaRemota.setBorderPainted(false);
        BTN_cartaRemota.setContentAreaFilled(false);

        BTN_cartaLocal.setBorder(null);
        BTN_cartaLocal.setBorderPainted(false);
        BTN_cartaLocal.setContentAreaFilled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BTN_cartaRemota, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbRealizar)
                    .addComponent(jbConsultar)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                        .addComponent(jbAbandonar, javax.swing.GroupLayout.Alignment.LEADING)))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jcCaracteristica, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jlTitulos, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jlPuntos, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(BTN_cartaLocal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcOpcion, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(BTN_cartaRemota, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbAbandonar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbConsultar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbRealizar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 199, Short.MAX_VALUE))
                    .addComponent(BTN_cartaLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jcOpcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcCaracteristica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlTitulos)
                    .addComponent(jlPuntos, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jlJugador2.setText("jLabel1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(109, 109, 109)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(214, 214, 214)
                                .addComponent(jlJugador1))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(346, 346, 346)
                                .addComponent(jlTurno, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 112, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlJugador2))
                        .addGap(278, 278, 278)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addComponent(jlTurno, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(488, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(32, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlJugador2)
                    .addComponent(jlJugador1))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-813)/2, (screenSize.height-600)/2, 813, 600);
    }// </editor-fold>//GEN-END:initComponents

    private void jbRealizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRealizarActionPerformed
        // TODO add your handling code here:

        if ((jcCaracteristica.getSelectedIndex() == 0) || (jcOpcion.getSelectedIndex() == 0)) {
            JOptionPane.showMessageDialog(null, "Seleccione una caracteristica y apuesta", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
        } else {
            this.jtMesa.setText("");
            this.jtMesa.setBackground(Color.WHITE);
            this.jlJugador1.setForeground(Color.BLACK);
            socket.send("1" + jcCaracteristica.getSelectedItem().toString());
            socket.send("2" + jcOpcion.getSelectedItem().toString());
        }
    }//GEN-LAST:event_jbRealizarActionPerformed

    private void jbAbandonarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAbandonarActionPerformed
        // TODO add your handling code here:
        socket.send("3");
        this.dispose();
        try {
            this.ij.dispose();
        } catch (Exception e) {
        }
    }//GEN-LAST:event_jbAbandonarActionPerformed

    private void jbConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbConsultarActionPerformed
        // TODO add your handling code here:
        this.jugadores.add(this.jlJugador1.getText());
        this.jugadores.add("Anfitrion");
        this.puntajes.add("" + puntaje);
        this.puntajes.add("" + puntajeAnfitrion);
        ij = new InformeJuego(jugadores, puntajes, empates);
        ij.setVisible(true);
    }//GEN-LAST:event_jbConsultarActionPerformed

    /**
     * @param args the command line arguments
     *//*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Tablero_1().setVisible(true);
            }
        });
    }*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTN_cartaLocal;
    private javax.swing.JButton BTN_cartaRemota;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbAbandonar;
    private javax.swing.JButton jbConsultar;
    private javax.swing.JButton jbRealizar;
    private javax.swing.JComboBox jcCaracteristica;
    private javax.swing.JComboBox jcOpcion;
    private javax.swing.JLabel jlJugador1;
    private javax.swing.JLabel jlJugador2;
    private javax.swing.JLabel jlPuntos;
    private javax.swing.JLabel jlTitulos;
    private javax.swing.JLabel jlTurno;
    private javax.swing.JTextArea jtMesa;
    // End of variables declaration//GEN-END:variables

    public void receiveData(String data) {

        if (data.substring(0, 1).equalsIgnoreCase("1")) // la carta
        {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(1))) {

                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaLocal.setIcon(imagenFondo);
                    this.BTN_cartaLocal.setRolloverIcon(imagenFondoR);

                }

            }
        } else if (data.substring(0, 1).equalsIgnoreCase("2")) {

            this.jlJugador1.setText(data.substring(1));

            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(1))) {

                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaRemota.setIcon(imagenFondo);
                    this.BTN_cartaRemota.setRolloverIcon(imagenFondoR);

                }
            }

        } else if (data.substring(0, 1).equalsIgnoreCase("3")) {

            this.jlTurno.setText("Anfitrión");
            this.jlTurno.setForeground(Color.RED);
            JOptionPane.showMessageDialog(null, "Empieza Anfitrión", "TURNO", JOptionPane.INFORMATION_MESSAGE);
            this.jbRealizar.setEnabled(false);
            this.jcOpcion.setEnabled(false);
            this.jcCaracteristica.setEnabled(false);
            this.jbAbandonar.setEnabled(true);
            this.jbConsultar.setEnabled(true);
        } else if (data.substring(0, 1).equalsIgnoreCase("4")) {
            this.jlTurno.setText("Jugador1");
            this.jlTurno.setForeground(Color.RED);
            JOptionPane.showMessageDialog(null, "Empieza Jugador1", "TURNO", JOptionPane.INFORMATION_MESSAGE);
            this.jbRealizar.setEnabled(true);
            this.jcOpcion.setEnabled(true);
            this.jcCaracteristica.setEnabled(true);
            this.jbAbandonar.setEnabled(true);
            this.jbConsultar.setEnabled(true);
        } else if (data.substring(0, 1).equalsIgnoreCase("5")) //cartas a la mesa
        {
            int aux = data.length();
            this.jtMesa.setText(data.substring(1));
            System.out.println(data.substring(1, aux - 1));

        } else if (data.substring(0, 1).equalsIgnoreCase("6")) {
            if (data.substring(1).equalsIgnoreCase("0")) // cero si gana jugador1 y 1 si fue anfitrion
            {
                this.jlTurno.setText("Jugador1");

                this.jlTurno.setForeground(Color.CYAN);
                this.jtMesa.setBackground(Color.GREEN);
                this.jbRealizar.setEnabled(true);
                this.jcOpcion.setEnabled(true);
                this.jcCaracteristica.setEnabled(true);
            } else {

                this.jlTurno.setText("Anfitrión");

                this.jlTurno.setForeground(Color.RED);
                this.jlJugador1.setForeground(Color.RED);
                this.jbRealizar.setEnabled(false);
                this.jcOpcion.setEnabled(false);
                this.jcCaracteristica.setEnabled(false);
            }
        } else if (data.substring(0, 1).equalsIgnoreCase("7")) //gana jugador
        {
            JOptionPane.showMessageDialog(null, "Anfitrion", "GANADOR", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);
            
        } else if (data.substring(0, 1).equalsIgnoreCase("8"))//gana anfitrion
        {
            JOptionPane.showMessageDialog(null, "Jugador1", "GANADOR", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);
            
        } else if (data.substring(0, 1).equalsIgnoreCase("9")) // empate
        {
            this.jtMesa.setBackground(Color.PINK);
            JOptionPane.showMessageDialog(null, "Empate", "EMPATE", JOptionPane.INFORMATION_MESSAGE);
            empates++;
        } else if (data.substring(0, 2).equalsIgnoreCase("A0")) //puntos de jugador
        {
            puntaje = new String(data.substring(2));
            System.out.println("Puntaje: " + puntaje);
            this.jlPuntos.setText(puntaje);
        } else if (data.substring(0, 2).equalsIgnoreCase("A1")) //puntos anfitrion
        {
            puntajeAnfitrion = new String(data.substring(2));
        } else if (data.substring(0, 2).equalsIgnoreCase("A3")) {
            JOptionPane.showMessageDialog(null, "El Anfitrión abandono la parida", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            try {
                this.ij.dispose();
            } catch (Exception e) {
            }
        } else if (data.substring(0, 2).equalsIgnoreCase("A4")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaRemota.setIcon(imagenFondo);
                    this.BTN_cartaRemota.setRolloverIcon(imagenFondoR);
                }
            }
        } else if (data.substring(0, 2).equalsIgnoreCase("A5")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaLocal.setIcon(imagenFondo);
                    this.BTN_cartaLocal.setRolloverIcon(imagenFondoR);
                }
            }
        } else if (data.substring(0, 2).equalsIgnoreCase("A6")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaRemota.setIcon(imagenFondo);
                    this.BTN_cartaRemota.setRolloverIcon(imagenFondoR);
                }
            }
        } else if (data.substring(0, 2).equalsIgnoreCase("A7")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaLocal.setIcon(imagenFondo);
                    this.BTN_cartaLocal.setRolloverIcon(imagenFondoR);
                }
            }
        }
        else if (data.substring(0, 2).equalsIgnoreCase("A8")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaRemota.setIcon(imagenFondo);
                    this.BTN_cartaRemota.setRolloverIcon(imagenFondoR);
                }
            }
        } else if (data.substring(0, 2).equalsIgnoreCase("A9")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaLocal.setIcon(imagenFondo);
                    this.BTN_cartaLocal.setRolloverIcon(imagenFondoR);
                }
            }
        }
        else if (data.substring(0, 2).equalsIgnoreCase("A10")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaRemota.setIcon(imagenFondo);
                    this.BTN_cartaRemota.setRolloverIcon(imagenFondoR);
                }
            }
        } else if (data.substring(0, 2).equalsIgnoreCase("A11")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaLocal.setIcon(imagenFondo);
                    this.BTN_cartaLocal.setRolloverIcon(imagenFondoR);
                }
            }
        }
         else if (data.substring(0, 2).equalsIgnoreCase("AA1")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaRemota.setIcon(imagenFondo);
                    this.BTN_cartaRemota.setRolloverIcon(imagenFondoR);
                }
            }
        } else if (data.substring(0, 2).equalsIgnoreCase("AA2")) {
            for (int i = 0; i < this.cartas.size(); i++) {
                if (this.cartas.get(i).getNombrePelicula().equalsIgnoreCase(data.substring(2))) {
                    ImageIcon imagenFondo = new ImageIcon();
                    ImageIcon imagenFondoR= new ImageIcon();
                    imagenFondo = new ImageIcon(getClass().getResource(this.cartas.get(i).getURL()));
                    imagenFondoR= new ImageIcon(getClass().getResource(this.cartas.get(i).getURLR()));
                    this.BTN_cartaLocal.setIcon(imagenFondo);
                    this.BTN_cartaLocal.setRolloverIcon(imagenFondoR);
                }
            }
        }
    }

    public void Iniciar(String ip, int host) {
        int p = 0;
        socket = new SocketClient(ip, host, this);
        socket.send("hola soy cliente");
        this.jProgressBar1.setIndeterminate(true);
        this.jlPuntos.setText("0.0");
    }
}
